package com.tjhk.netty.serialize;

import com.tjhk.netty.serialize.annotation.Field;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

public class BasicField {
    protected static Logger log = LoggerFactory.getLogger(BasicField.class.getSimpleName());

    protected final int index;
    protected final int length;
    protected final String desc;
    protected final Method readMethod;
    protected final Method writeMethod;
    protected final PropertyDescriptor property;
    protected final Field field;
    /** 参数类型 **/
    protected final Class<?> fieldType;
    public BasicField(Field field, PropertyDescriptor property, Class<?> fieldType) {
        this.index = field.index();
        this.fieldType = fieldType;
        int length = field.length();
        if (length < 0)
            length = field.type().length;
        this.length = length;
        this.desc = field.desc();
        this.readMethod = property.getReadMethod();
        this.writeMethod = property.getWriteMethod();
        this.field = field;
        this.property = property;
    }

    public int getIndex() {
        return index;
    }

    public int getLength() {
        return length;
    }

    public String getDesc() {
        return desc;
    }

    public Method getReadMethod() {
        return readMethod;
    }

    public Method getWriteMethod() {
        return writeMethod;
    }

    public PropertyDescriptor getProperty() {
        return property;
    }

    public Field getField() {
        return field;
    }

    public Class<?> getFieldType() {
        return fieldType;
    }
}
